<template>
  <div>

      <!-- 内容列表 -->
      <div class="table-container select-table">
        <el-table ref="multipleTable" :data="dataList"
                  element-loading-text="加载中" style="width: 100%">
          <el-table-column width="60px" label="序号" align="center">
            <template slot-scope="scope">
              <el-input class="no-input" v-model="scope.row.sortNo" @change="listData(scope.row)"/>
            </template>
          </el-table-column>
          <el-table-column width="380px" label="商品" prop="title" >
            <template slot-scope="scope">
              <div class="flex v-align-c cursor-p">
                <label><img :src="scope.row.imageUrl" class="picture-avatar"></label>
                <div class="font-14 pad-l-10">
                  <div class="title-line-2 font-14">{{scope.row.title}}</div>
                  <template v-if="scope.row.categoryName">
                    <div class="pad-t-6">
                      <span class="category-style">[{{scope.row.categoryName}}]</span>
                      <el-tag class="mar-l-10" size="mini" v-if="scope.row.skuFlag === 1" effect="light">多规格</el-tag>
                    </div>
                  </template>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column width="80px" label="零售价格" prop="sellPrice" align="center">
            <template slot-scope="scope">
              ￥{{scope.row.sellPrice}}
            </template>
          </el-table-column>
          <el-table-column width="180px" label="分销佣金" align="center">
            <template slot-scope="scope">
              <div class="flex v-align-c mar-b-5">
                <el-input placeholder="请输入价格" class="set-s-p-input" style="width: 65px" v-model="scope.row.distributeIncome"/>
              </div>
            </template>
          </el-table-column>
          <el-table-column width="180px" label="顾客分销商佣金" align="center">
            <template slot-scope="scope">
              <div class="flex v-align-c mar-b-5">
                <el-input placeholder="请输入价格" class="set-s-p-input" style="width: 65px" v-model="scope.row.shareMemberIncome"/>
              </div>
            </template>
          </el-table-column>
          <el-table-column width="100px" label="销量" align="center">
            <template slot-scope="scope">
              {{scope.row.salesNum}}
            </template>
          </el-table-column>
          <el-table-column width="160px" label="活动价" prop="skuFlag" align="center">
            <template slot-scope="scope">
              <el-input v-if="scope.row.skuFlag !== 1" placeholder="请输入活动价" class="set-p-input" v-model="scope.row.promotionPrice" @change="changePrice(scope.row)"/>
              <el-button v-else type="primary" plain size="small" @click="setActivePrice(scope.row)" class="set-p-btn">设置活动价</el-button>
                <template v-if="getPerfectInfo(scope.row) == '1'">
                  <br><a style="color: #00b200">已完善</a>
                </template>
                <template v-else>
                  <br><a >待完善</a>
                </template>
            </template>
          </el-table-column>
          <el-table-column width="100px" label="操作" align="center">
            <template slot-scope="scope">
              <el-button type="text" class="del-t-btn" @click="deleteItem(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
  </div>

</template>
<script>
  export default {
    data() {
      return {
        dataList: []
      }
    },
    // 初始化页面
    created() {
      console.log('item-list')
    },
    mounted() {
      const that = this
      this.$bus.$on('promotion-sku-price-save', function(goodsInfo) {
        const goodsId = goodsInfo.goodsId
        const dataList = that.dataList
        dataList.forEach(obj => {
          if (obj.goodsId === goodsId) {
            obj.promotionGoodsSkuList = goodsInfo.promotionGoodsSkuList
            const promotionPrice = Math.min.apply(Math, goodsInfo.promotionGoodsSkuList.map(function(o) { return o.promotionPrice }))
            obj.promotionPrice = promotionPrice
          }
        })
        this.dataList = dataList
        that.updateData(dataList)
      })
      // 更新监听
      this.$bus.$on('promotion-update', function(data) {
        that.dataList = data.promotionGoodsList
        that.updateData(data.promotionGoodsList)
      })
    },
    filters: {
    },
    methods: {
      changePrice(row) {
        this.$bus.$emit('promotion-item-phone', row.goodsId)
      },
      setActivePrice(row) {
        this.$bus.$emit('promotion-sku-price-open', row)
      },
      deleteItem(item) {
        // 删除商品
        const dataList = this.dataList
        dataList.splice(dataList.findIndex(obj => item.goodsId === obj.goodsId), 1)
        this.dataList = dataList
        this.listData()
        this.updateData(dataList)
      },
      listData() {
        const dataList = this.dataList
        dataList.sort((a, b) => { return a.sortNo - b.sortNo })
        for (let i = 0; i < dataList.length; i++) {
          dataList[i].sortNo = i + 1
        }
        this.dataList = dataList
      },
      changeData() {
        const dataList = this.dataList
        this.updateData(dataList)
      },
      getPerfectInfo(row) {
        const skuFlag = row.skuFlag
        let ret = 1
        if (skuFlag === 1) {
          const skuList = row.promotionGoodsSkuList
          skuList.forEach(e => {
            const promotionPrice = e.promotionPrice
            if (!this.$utils.isExist(promotionPrice) || promotionPrice === 0 || promotionPrice === '0' || promotionPrice === '0.0' || promotionPrice === '0.00') {
              ret = 0
            }
          })
        } else {
          const promotionPrice = row.promotionPrice
          if (promotionPrice === null || promotionPrice * 1 === 0) {
            ret = 0
          }
        }
        return ret
      },
      // 更新数据(其他组件勾选有使用)
      updateData(dataList) {
        this.dataList = dataList
        this.listData()
        const data = this.dataList
        this.$bus.$emit('promotion-phone', data)
      }
    }
  }
</script>
<style lang="less" scoped>
  // 页面总体布局
  .active-main{
    background: #f8f8f8;
    &:after{
      content: '';
      display: block;
      clear: both;
      font-size: 0;
    }
    .active-l{
      .main-content{
        padding-right: 4px;
        padding-left: 2px;
        height: 570px;
        overflow-x: hidden;
        overflow-y: auto;
        &::-webkit-scrollbar {
          width: 4px;
        }
        &::-webkit-scrollbar-thumb {
          border-radius: 10px;
          box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
          -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
          background: rgba(0,0,0,0.2);
        }
        &::-webkit-scrollbar-track {
          box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
          -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
          border-radius: 0;
          background: rgba(0,0,0,0.1);
        }
        h2{
          margin: 0;
          font-size: 18px;
        }
        ul{
          padding: 0;
          margin: 0;
          &:after{
            content: '';
            display: block;
            clear: both;
            font-size: 0;
          }
          &.show-type-1{
            li{
              .gooods-pic{
                img{
                  width: 100%;
                  height: 149px;
                  border-top-left-radius: 4px;
                  border-top-right-radius: 4px;
                }
              }
            }
          }
          &.show-type-2{
            li{
              width: 48%;
              float: left;
              &:nth-child(odd){
                margin-right: 4%;
              }
              .gooods-pic{
                img{
                  width: 100%;
                  height: 133px;
                  border-top-left-radius: 4px;
                  border-top-right-radius: 4px;
                }
              }
              .buy-now-type{
                display: none;
              }
              .price{
                label{
                  display: none;
                }
              }
            }
          }
          &.show-type-3{
            li{
              display: -webkit-box;
              display: -webkit-flex;
              display: flex;
              flex-flow: row;
              align-items: center;
              padding: 0 5px 0 8px;
              .pic-box{
                margin-right: 6px;
                .gooods-pic{
                  img{
                    width: 82px;
                    height: 82px;
                  }
                }
              }
              .detail-box{
                -webkit-box-flex: 1;
                -webkit-flex: 1;
                flex: 1;
              }
              .tag{
                span{
                  padding: 1px 5px!important;
                }
                label{
                  padding: 1px 5px!important;
                }
              }
              .price{
                label{
                  display: none;
                }
              }
              .stock{
                display: none;
              }
            }
          }
          &.show-type-4{
            li{
              display: -webkit-box;
              display: -webkit-flex;
              display: flex;
              flex-flow: row;
              align-items: center;
              padding: 8px 5px 8px 8px;
              &:nth-child(even){
                .pic-box{
                  &.even{
                    display: none;
                  }
                  &.odd{
                    display: block;
                  }
                }
              }
              &:nth-child(odd){
                .pic-box{
                  &.even{
                    display: block;
                  }
                  &.odd{
                    display: none;
                  }
                }
              }
              .pic-box{
                margin-right: 6px;
                .gooods-pic{
                  img{
                    width: 122px;
                    height: 122px;
                  }
                }
              }
              .detail-box{
                -webkit-box-flex: 1;
                -webkit-flex: 1;
                flex: 1;
                padding: 0 6px!important;
              }
              .desc{
                margin-top: -6px;
              }
              .tag{
                margin-top: -1px;
                margin-bottom: 0px;
                span{
                  padding: 1px 5px!important;
                }
                label{
                  padding: 1px 5px!important;
                }
              }
              .price{
                .flex-item{
                  >label{
                    display: -webkit-box;
                    display: -webkit-flex;
                    display: flex;
                    margin-top: -8px;
                  }
                }
              }
              .stock{
                display: none;
              }
              .info-bar{
                .buy-now-type{
                  display: none!important;
                }
              }
              .last-item{
                display: block!important;
                margin-top: 5px;
              }
            }
          }
          li{
            list-style-type: none;
            border-radius: 4px;
            box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
            margin-bottom: 15px;
            &:last-child{
              margin-bottom: 0;
            }
            .pic-box{
              &.odd{
                display: none;
              }
            }
            .gooods-pic{
              img{
                display: block;
              }
            }
            .desc{
              height: 36px;
              line-height: 1.5;
              overflow:hidden;
              text-overflow:ellipsis;
              display:-webkit-box;
              -webkit-line-clamp:2;
              -webkit-box-orient:vertical;
              word-break:break-word;
            }
            .last-item{
              display: none;
            }
            .info-bar{
              .tag{
                line-height: 1.3;
                span{
                  background: #fed807;
                  color: #333;
                  padding: 2px 5px;
                }
                label{
                  background: #272727;
                  color: #fff;
                  padding: 2px 5px;
                  min-width: 60px;
                  box-sizing: border-box;
                  i{
                    color: #ffc81b;
                    font-style: normal;
                  }
                }
              }
              .price{
                span{
                  color: #FF4949;
                }
                label{
                  text-decoration: line-through;
                }
              }
              .stock{
                color: #6e6e6e;
              }
              label{
                font-weight: normal;
              }
            }
          }
        }
        .picture-default{
          background: #fe8096;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
    }
    .active-r{
      border: 1px solid #ddd;
      border-radius: 10px;
      background: #fff;
      padding: 20px;
      min-height: 609px;
      h2{
        font-size: 18px;
        margin: 0;
      }
      .tips{
        color: #409eff;
      }
      .select-table{
        min-height: auto!important;
      }
    }
  }
  .category-style {
    color: #6290ff;
    font-size: 13px;
  }
  .title-line-2{
    height: 40px;
    line-height: 1.4;
    overflow:hidden;
    text-overflow:ellipsis;
    display:-webkit-box;
    -webkit-line-clamp:2;
    -webkit-box-orient:vertical;
    word-break:break-word;
  }
  // 商品弹窗样式
  .goods-layer{
    h3{
      margin: -10px 0 0 0;
      color: #303133;
      font-size: 18px;
      text-align: center;
    }
    .dialog-footer{
      position: absolute;
      left: 0;
      bottom: 20px;
      width: 100%;
    }
    .table-container{
      height: 500px;
      overflow-x: hidden;
      overflow-y: auto;
    }
  }
  // 左侧手机模型样式
  .diy-bg-main{
    .diy-phone {
      float: left;
      width: 340px;
      border: 1px solid #ddd;
      border-radius: 10px;
      background: #fff;
      padding: 10px;
      overflow: hidden;
      &.none-border{
        border: none;
        background: none;
        padding: 0px 10px;
        border-radius: 0;
      }
    }
    .diy-phone .phone-head {
      height: 44px;
      background: #fff;
      position: relative;
    }
    .diy-phone .phone-head:before {
      content: "";
      position: absolute;
      top: 15px;
      left: 112px;
      height: 8px;
      width: 8px;
      background: #ddd;
      border-radius: 8px;
    }
    .diy-phone .phone-head:after {
      content: "";
      position: absolute;
      top: 15px;
      left: 128px;
      height: 8px;
      width: 50px;
      background: #ddd;
      border-radius: 8px;
    }
    .diy-phone .phone-title {
      height: 17px;
      background: url(../../../../assets/images/wx-top-2.png) 0 0 no-repeat;
      background-size: 100% auto;
      padding: 0 50px;
      font-size: 15px;
      color: #333333;
      text-align: center;
      line-height: 68px;
      cursor: default;
      overflow: hidden;
      display: block;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }
</style>

